home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Hot Mix 17
/
Hot Mix 17.iso
/
HM17_SGI
/
html
/
cgi-bin
/
mailform.cgi
< prev
next >
Wrap
Text File
|
1997-06-17
|
11KB
|
367 lines
#!/usr/bin/perl
# $Id: mailform.general,v 1.18 1996/11/08 02:57:25 kwong Exp $
#
# mailform.general - cgi script for mailing form output
# The following hidden fields are supported:
# encrypt - The outgoing mail will be encrypted using the
# destination user's public key
# <INPUT TYPE="hidden" NAME="encrypt">
# footer - specifies additional footer icons
# <INPUT TYPE="hidden" NAME="footer" VALUE="section:url:icon">
# section - the section name (alt text or text if no icon)
# url - the URL to link to
# icon - image URL to display (optional)
# nofieldnames - eliminates printing of the field names
# <INPUT TYPE="hidden" NAME="nofieldnames">
# nospecial - keep special fields in the form (ie e-mail, name)
# <INPUT TYPE="hidden" NAME="nospecial">
# required - The fields specified are required for form
# submission. For this field, "name" is the name
# of the field, and "text" is the text to display
# as a field description. For multiple required
# fields, use multiple hidden lines.
# <INPUT TYPE="hidden" NAME="required" VALUE="name:text">
# response - The value of this field will be used as the
# document to send for the response to submitting
# the form. The filename must be a full path
# relative to the DocumentRoot.
# <INPUT TYPE="hidden" NAME="response" VALUE="/filename">
# separator - specifies the field separator (defaults to \n)
# <INPUT TYPE="hidden" NAME="separator" VALUE="\t">
# sort - causes the output to be sorted by field name
# <INPUT TYPE="hidden" NAME="sort">
#
# $Log: mailform.general,v $
# Revision 1.18 1996/11/08 02:57:25 kwong
# At strip out code for \0 for non sort
#
# Revision 1.17 1996/09/19 17:55:12 kwong
# .
#
# Revision 1.16 1996/09/16 18:56:14 kwong
# .
#
# Revision 1.15 1996/06/12 20:41:27 kwong
# .
#
# Revision 1.14 1995/11/09 20:48:45 drich
# fixed a nospecial bug
#
# Revision 1.13 1995/11/08 18:19:59 drich
# added field seperator and nospecial fields
#
# Revision 1.12 1995/10/24 23:54:25 drich
# fixed docs, and added nofieldnames option
#
# Revision 1.11 1995/10/07 02:41:44 drich
# fixed e-mail and subject fields
#
# Revision 1.10 1995/09/18 22:21:22 drich
# fixed wording on error form
#
# Revision 1.9 1995/09/16 04:44:38 drich
# changed footers tag to footer
#
# Revision 1.8 1995/09/16 04:06:53 drich
# more footer fixes
#
# Revision 1.7 1995/09/16 03:47:39 drich
# fixed footer bug
#
# Revision 1.6 1995/09/16 03:45:05 drich
# added footer documentation
#
# Revision 1.5 1995/09/16 03:35:59 drich
# Fixed bug for multiple required fields
#
# Revision 1.4 1995/09/16 00:09:35 kwong
# .
#
# Revision 1.3 1995/09/15 22:10:18 drich
# added lots of options
#
# Revision 1.2 1995/06/16 17:57:29 drich
# Added support for CC to webmaster if from the feedback form
#
# Revision 1.1 1995/02/12 00:06:22 drich
# Initial revision
#
#
# Get potential include path
($dirname,$basename) = ($0 =~ (/^(.*)\/([^\/]*)$/));
push(@INC,$dirname) if ($dirname);
require('cgi-lib-g.pl') || die "can\'t require cgi-lib.pl: $!";
require('surf-lib-g.pl') || die "can\'t require surf-lib.pl: $!";
$request_method = $ENV{'REQUEST_METHOD'};
$query_string = $ENV{'QUERY_STRING'};
$path_info = $ENV{'PATH_INFO'};
$path_info =~ s/^\///; $path_info =~ s/\// /;
$content_length = $ENV{'CONTENT_LENGTH'};
sub error {
local(@error) = @_;
&header("Mailform error!!");
print "<B>\n";
print "There has been an error processing your mailform submission.\n";
print "</B><P><PRE>\n";
foreach $_ (@error) {
print $_;
}
print "</PRE>\n";
&footer;
exit;
}
# Save any error output
close(STDERR);
open(STDERR,">/usr/tmp/mailform$$.log") || die "can\'t open logfile:/usr/tmp/mailform$$.log: $!";
&ReadParse();
# Get "special" entries
foreach $key (keys %in) {
$email = $key if (($key =~ /e-*mail/i) && ($in{$key} =~ /\@/));
$name = $key if ($key =~ /name/i);
$subject = $key if ($key =~ /subject/i);
$comment = $key if ($key =~ /comments*/i);
}
# Check for hidden fields to set options
$sort = $in{'sort'} ? true : 0; # Should the output be sorted?
$sep = $in{'separator'} ? $in{'separator'} : "\n";
$nospecial = $in{'nospecial'}; #
@required = split(/\\0/,$in{'required'}); # Required field names (name:text)
$encrypt = $in{'encrypt'};
$response = $in{'response'}; # Custom response?
@footers = split(/\\0/,$in{'footer'}); # Footer information
# Convert @footers to @sections for &footer
foreach $footer (@footers) {
($section,$url,$icon) = split(':',$footer);
push(@sections,$section);
$name{$section} = $section;
$root{$section} = $url;
$icon_url{$section} = $icon if ($icon);
}
foreach $info (@required) {
($field,$fname) = split(':',$info);
$missing = !$in{$field} unless($missing);
}
if ($missing) {
&header("Missing information....");
print <<"EOF";
I'm sorry, but you haven't entered all of the required information on the
form. The form may not be submitted until the following information is provided:
<P>
EOF
print "<UL>\n";
foreach $info (@required) {
($field,$fname) = split(':',$info);
$fname = $field unless($fname);
$fname =~ s/_/ /g;
print " <LI>$fname\n" unless($in{$field});
}
print "</UL>\n";
print " <P>\n";
# if (! $in{'DocName'}) {
# $in{'DocName'} = $ENV{'HTTP_REFERER'};
# }
($server,$path) = ($in{'DocName'} =~ /http:\/\/([^\/:]+):*\d*\/(.*)$/);
if ($server && $server_name =~ /^$server/ && -f "$DocumentRoot/$path") {
print "<HR><BR>\n";
open(DOC,"$DocumentRoot/$path");
while(<DOC>) {
$_ = $save . $_; # Saved line from last time
unless (/</) {
print $_;
undef($save);
next;
}
if (/<\/FORM>/i) {
print "<INPUT TYPE=\"hidden\" NAME=\"DocName\" VALUE=\"$in{'DocName'}\">\n";
}
($name) = /NAME\s*=\s*\"([^\"]+)"/i;
($type) = /TYPE\s*=\s*\"([^\"]+)"/i;
if (!$name || $type =~ /hidden/i) { # Print hidden fields as-is
print $_;
undef($save);
next;
}
if (/TEXTAREA/i) {
print $_;
print "$in{$name}\n";
undef($save);
next;
}
if ($in{$name}) {
if (/VALUE=/i) {
s/(VALUE\s*=\s*\")[^\"]*\"/$1$in{$name}\"/i;
} else {
s/(NAME\s*=\s*\"[^\"]*\")/$1 VALUE=\"$in{$name}\"/i;
}
}
print $_;
undef($save);
}
close(DOC);
} else {
&footer;
}
unlink("/usr/tmp/mailform$$.head.out");
unlink("/usr/tmp/mailform$$.body.out");
unlink("/usr/tmp/mailform$$.log");
exit 0;
}
open(TMPMAILHEAD,">/usr/tmp/mailform$$.head.out") ||
die "can\'t open /usr/tmp/mailform$$.head.out: $!";
if ($in{$email}) {
# open(MAIL,"|/usr/lib/sendmail -t -f $in{$email}");
print TMPMAILHEAD "To: $path_info\n";
if (defined $in{$name}) {
print TMPMAILHEAD "From: $in{$email} ($in{$name})\n";
} else {
print TMPMAILHEAD "From: $in{$email}\n";
}
} else {
# open(MAIL,"|/usr/lib/sendmail -t");
print TMPMAILHEAD "To: $path_info\n";
print TMPMAILHEAD "From: Nobody\n";
}
print TMPMAILHEAD "Reply-To: $in{$email}\n" if ($in{$email});
print TMPMAILHEAD "Cc: webmaster\@www.sgi.com\n" if (($path_info !~ /^webmaster/) &&
($ENV{'HTTP_REFERER'} =~ /form_feedback/));
if (defined $in{$subject}) {
print TMPMAILHEAD "Subject: $in{$subject}\n";
} else {
print TMPMAILHEAD "Subject: Mail from WWW\n";
}
print TMPMAILHEAD "Precedence: bulk\n";
print TMPMAILHEAD "\n";
close(TMPMAILHEAD);
# Encrypt it if needed
if ($encrypt) {
$ENV{'PGPPATH'} = "/www/.pgp";
open(TMPMAILBODY,"| pgp +batchmode +force -fea $path_info > /usr/tmp/mailform$$.body.out") || die "can't start pgp: $!";
push(@pgpout,"pgp +batchmode +force -fea $path_info > /usr/tmp/mailform$$.body.out\n");
} else {
open(TMPMAILBODY,">/usr/tmp/mailform$$.body.out") ||
die "can\'t open /usr/tmp/mailform$$.body.out: $!";
}
# Loop through fields, print fieldname: contents
if ($sort) {
foreach $key (sort keys %in) {
($pkey = $key) =~ s/^(\d+)//;
next if ($pkey =~ /^($email|$subject|$comment)$/ && !$nospecial);
next if ($pkey =~ /^(required|encrypt|sort|response|footers|nofieldname|nospecial|separator|footer)$/);
$in{$key} =~ s/\\0/; /g;
$in{$key} =~ s/^\s+; //;
print TMPMAILBODY "$pkey: " unless ($in{'nofieldname'});
eval "print TMPMAILBODY \"\$in{\$key}$sep\"";
}
} else {
foreach $key (keys %in) {
($pkey = $key) =~ s/^(\d+)//;
next if ($pkey =~ /^($email|$subject|$comment)$/ && !$nospecial);
next if ($pkey =~ /^(required|encrypt|sort|response|footers|nofieldname|nospecial|separator|footer)$/);
($pkey = $key) =~ s/^(\d+)//;
$in{$key} =~ s/\\0/; /g;
$in{$key} =~ s/^\s+; //;
print TMPMAILBODY "$pkey: " unless ($in{'nofieldname'});
eval "print TMPMAILBODY \"\$in{\$key}$sep\"";
# print TMPMAILBODY "$in{$key}$sep";
}
}
# Place comments as the body of the e-mail
unless ($nospecial) {
print TMPMAILBODY "\n$in{$comment}\n" if ($in{$comment});
print TMPMAILBODY "\n";
print TMPMAILBODY "-- \n";
}
# Also generate a line to track what host sent it, just in case we
# get a bogus e-mail address.
print TMPMAILBODY "Received from: $ENV{'REMOTE_USER'}@$ENV{'REMOTE_HOST'}($ENV{'REMOTE_ADDR'})\n";
close(TMPMAILBODY);
close(STDERR);
# Get pgp output
open(LOG,"</usr/tmp/mailform$$.log");
while(<LOG>) {
push(@pgpout,$_);
}
close(LOG);
&error(@pgpout) if grep(/Invalid|usage:/,@pgpout);
# Actually send the e-mail
if ($in{$email}) {
open(MAIL,"|/usr/lib/sendmail -t -f $in{$email}");
} else {
open(MAIL,"|/usr/lib/sendmail -t");
}
open(TMPMAIL,"/usr/tmp/mailform$$.head.out") ||
die "can\'t open /usr/tmp/mailform$$.head.out for input: $!";
while(<TMPMAIL>) {
print MAIL $_;
}
close(TMPMAIL);
open(TMPMAIL,"/usr/tmp/mailform$$.body.out") ||
die "can\'t open /usr/tmp/mailform$$.body.out for input: $!";
while(<TMPMAIL>) {
print MAIL $_;
}
close(TMPMAIL);
close(MAIL);
# Cleanup after ourselves
unlink("/usr/tmp/mailform$$.head.out");
unlink("/usr/tmp/mailform$$.body.out");
unlink("/usr/tmp/mailform$$.log");
if ($response &&
(($response =~ /^\// && open(FILE,"$DocumentRoot$response") ||
open(FILE,"$response")))) {
print "Content-type: text/html\n\n";
while (<FILE>) {
print $_;
}
} else {
&header("Thank you!");
print "<H2>Thank you for your comments!</H2>\n";
print "<H3>Your comments have been sent to $path_info</H3>";
&footer;
}
if ($in{'ftype'} eq "ffb"){
@temp = split (/;/,$in{$email});
foreach (@temp){
if (/\@/){
$in{$email} = $_;
last;
}
}
open (MAIL,"|/usr/lib/sendmail -t");
print MAIL "To: $in{$email}\n";
print MAIL "From: webmaster\@www.sgi.com (Electronic Marketing at Silicon Graphics, Inc.)\n";
print MAIL "Subject: Your Message to Silicon Surf\n";
open (TEMP ,"<./autoreply.txt");
while (<TEMP>){
print MAIL "$_";
}
close (TEMP);
close (MAIL);
}